/**
 * \file TimeMeasure_Linux.cpp
 * \brief TimeMeasure declaration class for Linux platforms
 * \author Edouard ROGE
 * \date 08 august 2012
 */

#include <sys/time.h>
#include <math.h>
#include "TimeMeasure.h"


TimeMeasure::TimeMeasure()
{
}

TimeMeasure::~TimeMeasure()
{
	m_Measures.clear();
}

uint32 TimeMeasure::AddMeasure()
{
	m_Mutex.Lock();
	m_Measures.resize(m_Measures.size()+2);
	m_Mutex.Unlock();
	return m_Measures.size()/2-1;
}

void TimeMeasure::Start(uint32 _iIndex)
{
	m_Mutex.Lock();
	gettimeofday(& (m_Measures[_iIndex*2]), NULL);
	m_Mutex.Unlock();
}

void TimeMeasure::Stop(uint32 _iIndex)
{
	m_Mutex.Lock();
	gettimeofday(& (m_Measures[_iIndex*2+1]), NULL);
	m_Mutex.Unlock();
}

float TimeMeasure::GetMeasure(int32 _iIndex) const
{
	return (m_Measures[2*_iIndex+1].tv_sec-m_Measures[2*_iIndex].tv_sec)*1000.0f+(m_Measures[2*_iIndex+1].tv_usec-m_Measures[2*_iIndex].tv_usec)/1000.0f;
}
